﻿@model CustomerRecurringPaymentListModel
@{
    Layout = "_ColumnsTwo";

    //title
    NopHtml.AddTitleParts(T("PageTitle.Account").Text);
    //page class
    NopHtml.AppendPageCssClassParts("html-account-page");
    NopHtml.AppendPageCssClassParts("html-order-list-page");

    var canRetryRecurringOrders = Model.RecurringPayments.Any(recurring => recurring.CanRetryLastPayment);
}
@section left
{
    @await Component.InvokeAsync(typeof(CustomerNavigationViewComponent), new { selectedTabId = CustomerNavigationEnum.RecurringPayments })
}
<div class="page account-page order-list-page">
    <div class="page-title">
        <h1>@T("Account.MyAccount") - @T("Account.CustomerOrders.RecurringOrders")</h1>
    </div>
    <div class="page-body">
        @if (Model.RecurringPayments.Count > 0)
        {
            <div class="section recurring-payments">
                <form asp-route="@NopRouteNames.Standard.CUSTOMER_RECURRING_PAYMENTS" method="post">
                    <div class="table-wrapper">
                        <table class="data-table">
                            <colgroup>
                                <col />
                                <col />
                                <col />
                                <col />
                                <col />
                                <col />
                                @if (canRetryRecurringOrders)
                                {
                                    <col />
                                }
                                <col />
                            </colgroup>
                            <thead>
                                <tr>
                                    <th class="start-date">
                                        @T("Account.CustomerOrders.RecurringOrders.StartDate")
                                    </th>
                                    <th class="cycle-info">
                                        @T("Account.CustomerOrders.RecurringOrders.CycleInfo")
                                    </th>
                                    <th class="next-payment">
                                        @T("Account.CustomerOrders.RecurringOrders.NextPayment")
                                    </th>
                                    <th class="total-cycles">
                                        @T("Account.CustomerOrders.RecurringOrders.TotalCycles")
                                    </th>
                                    <th class="cycles-remaining">
                                        @T("Account.CustomerOrders.RecurringOrders.TotalCycles")
                                    </th>
                                    <th class="initial-order">
                                        @T("Account.CustomerOrders.RecurringOrders.CyclesRemaining")
                                    </th>
                                    @if (canRetryRecurringOrders)
                                    {
                                        <th class="retry">
                                            @T("Account.CustomerOrders.RecurringOrders.RetryLastPayment")
                                        </th>
                                    }
                                    <th class="cancel">
                                        @T("Account.CustomerOrders.RecurringOrders.Cancel")
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model.RecurringPayments)
                                {
                                    <tr>
                                        <td class="start-date">
                                            @item.StartDate
                                        </td>
                                        <td class="cycle-info">
                                            @item.CycleInfo
                                        </td>
                                        <td class="next-payment">
                                            @item.NextPayment
                                        </td>
                                        <td class="total-cycles">
                                            @item.TotalCycles
                                        </td>
                                        <td class="cycles-remaining">
                                            @item.CyclesRemaining
                                        </td>
                                        <td class="initial-order">
                                            <a href="@Url.RouteUrl(NopRouteNames.Standard.ORDER_DETAILS, new { orderId = item.InitialOrderId })">@string.Format(T("Account.CustomerOrders.RecurringOrders.ViewInitialOrder").Text, item.InitialOrderNumber)</a>
                                        </td>
                                        @if (canRetryRecurringOrders)
                                        {
                                            <td class="retry">
                                                @if (item.CanRetryLastPayment)
                                                {
                                                    <button type="submit" name="retryLastPayment_@(item.Id)" class="button-2 retry-recurring-order-button">@T("Account.CustomerOrders.RecurringOrders.RetryLastPayment")</button>
                                                }
                                            </td>
                                        }
                                        <td class="cancel">
                                            @if (item.CanCancel)
                                            {
                                                <button type="submit" name="cancelRecurringPayment@(item.Id)" class="button-2 cancel-recurring-order-button">@T("Account.CustomerOrders.RecurringOrders.Cancel")</button>
                                            }
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </form>
            </div>
                if (Model.RecurringPaymentErrors.Any())
                {
                    <div class="message-error">
                        <ul>
                            @foreach (var error in Model.RecurringPaymentErrors)
                            {
                                <li>@error</li>
                            }
                        </ul>
                    </div>
                }
            }
            else
            {
                <div class="no-data">
                    @T("Account.CustomerRecurringPayments.NoPayments")
                </div>
            }
    </div>
</div>